﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;

namespace FubiManger.Controls
{
    ////ToolboxItem用于控制是否添加自定义控件到工具箱，true添加，false不添加
    //[System.ComponentModel.ToolboxItem(true)]
    partial class leveleditcontrol : Smobiler.Core.Controls.MobileUserControl
    {
        public leveleditcontrol() : base()
        {
            //This call is required by the SmobilerUserControl.
            InitializeComponent();
        }
        /// <summary>
        /// 等级名称
        /// </summary>
        public string levelname { get; set; }
        /// <summary>
        /// 金额
        /// </summary>
        public string amount { get; set; }
        /// <summary>
        /// 折扣
        /// </summary>
        public string discount_rate { get; set; }
        /// <summary>
        /// 等级ID
        /// </summary>
        public string levelid { get; set; }
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        private void txtvip1_TouchLeave(object sender, EventArgs e)
        {
            try
            {
                if (Convert.ToInt32(txtvip.Text) > 0 && Convert.ToInt32(txtdiscount_rate.Text) > 1)
                {
                    btnupdate.Visible = true;
                }
            }
            catch (Exception)
            {
                //txtdiscount_rate.Text = "0";
                //txtvip.Text = "0";
                //MessageBox.Show("请正确填写参数");
            }
        }
        /// <summary>
        /// 折扣
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtdiscount_rate1_TouchLeave(object sender, EventArgs e)
        {
            try
            {
                if (Convert.ToInt32(txtvip.Text) > 0 && Convert.ToInt32(txtdiscount_rate.Text) > 1)
                {
                    btnupdate.Visible = true;
                }
            }
            catch (Exception)
            {
                //txtdiscount_rate.Text = "0";
                //txtvip.Text = "0";
                //MessageBox.Show("请正确填写参数");
            }
        }

        private void leveleditcontrol_Load(object sender, EventArgs e)
        {
            switch (levelname)
            {
                case "LV1":
                    lbllevel.Text = "VIP一级";
                    break;
                case "LV2":
                    lbllevel.Text = "VIP二级";
                    break;
                case "LV3":
                    lbllevel.Text = "VIP三级";
                    break;
                case "LV4":
                    lbllevel.Text = "VIP四级";
                    break;
                case "LV5":
                    lbllevel.Text = "VIP五级";
                    break;
                case "LV6":
                    lbllevel.Text = "VIP六级";
                    break;
                case "LV7":
                    lbllevel.Text = "VIP七级";
                    break;
            }
            txtvip.Text = amount;//金额
            txtdiscount_rate.Text = discount_rate;//折扣
        }
        /// <summary>
        /// 更新规则
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnupdate_Press(object sender, EventArgs e)
        {
            try
            {
                if (Convert.ToInt32(txtvip.Text) > 0 && Convert.ToInt32(txtdiscount_rate.Text) > 1)
                {
                    merchant_levelDal.Updateamountbylevelid(levelname, levelid, txtvip.Text, txtdiscount_rate.Text);
                    Toast("规则更新成功");
                    btnupdate.Visible = false;
                }

                else
                {
                    MessageBox.Show("请正确填写参数");
                }
            }
            catch (Exception)
            {

                MessageBox.Show("请正确填写参数");
            }
            
        }

        private void txtdiscount_rate_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (Convert.ToInt32(txtvip.Text) > 0 && Convert.ToInt32(txtdiscount_rate.Text) > 1)
                {                   
                    btnupdate.Visible = true;
                }
            }
            catch (Exception)
            {
                //txtdiscount_rate.Text = "0";
                //txtvip.Text = "0";
                //MessageBox.Show("请正确填写参数");
            }
        }

        private void txtvip_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (Convert.ToInt32(txtvip.Text) > 0 && Convert.ToInt32(txtdiscount_rate.Text) > 1)
                {
                    btnupdate.Visible = true;
                }
            }
            catch (Exception)
            {
                //txtdiscount_rate.Text = "0";
                //txtvip.Text = "0";
                //MessageBox.Show("请正确填写参数");
            }
        }
    }
}